<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>对象的动态特性 | JavaScript高级讲义</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../Sources/dom操作复习.html" />
    
    
    <link rel="prev" href="../Sources/值类型和引用类型的特征.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.5"
        data-chapter-title="对象的动态特性"
        data-filepath="Sources/对象的动态特性.md"
        data-basepath=".."
        data-revision="Tue Oct 18 2016 20:46:48 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        JavaScript高级讲义
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="0.1" data-path="Sources/内容简介.html">
            
                
                    <a href="../Sources/内容简介.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>0.1.</b>
                        
                        内容简介
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> JavaScript基础知识复习</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="Sources/基础复习题.html">
            
                
                    <a href="../Sources/基础复习题.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        基础复习题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
            <span><b>1.2.</b> 内置对象与方法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="Sources/array.html">
            
                
                    <a href="../Sources/array.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.1.</b>
                        
                        Array
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="Sources/date.html">
            
                
                    <a href="../Sources/date.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.2.</b>
                        
                        Date
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="Sources/number.html">
            
                
                    <a href="../Sources/number.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.3.</b>
                        
                        Number
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="Sources/boolean.html">
            
                
                    <a href="../Sources/boolean.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.4.</b>
                        
                        Boolean
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="Sources/string.html">
            
                
                    <a href="../Sources/string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.5.</b>
                        
                        String
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="Sources/math.html">
            
                
                    <a href="../Sources/math.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.6.</b>
                        
                        Math
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Sources/值类型和引用类型.html">
            
                
                    <a href="../Sources/值类型和引用类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        值类型和引用类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="Sources/值类型和引用类型的特征.html">
            
                
                    <a href="../Sources/值类型和引用类型的特征.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        值类型和引用类型的特征
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.5" data-path="Sources/对象的动态特性.html">
            
                
                    <a href="../Sources/对象的动态特性.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        对象的动态特性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Sources/dom操作复习.html">
            
                
                    <a href="../Sources/dom操作复习.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        DOM操作复习
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="Sources/异常处理.html">
            
                
                    <a href="../Sources/异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Sources/调试工具的使用.html">
            
                
                    <a href="../Sources/调试工具的使用.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        调试工具的使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >JavaScript高级讲义</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x5BF9;&#x8C61;&#x7684;&#x52A8;&#x6001;&#x7279;&#x6027;">&#x5BF9;&#x8C61;&#x7684;&#x52A8;&#x6001;&#x7279;&#x6027;</h1>
<h2 id="1&#x3001;&#x7ED9;&#x5BF9;&#x8C61;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;">1&#x3001;&#x7ED9;&#x5BF9;&#x8C61;&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;</h2>
<p>&#x5F53;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x9700;&#x8981;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x7528;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x4E3A;&#x5176;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;</p>
<ul>
<li>&#x76F4;&#x63A5;&#x4F7F;&#x7528;<code>&#x5BF9;&#x8C61;&#x540D;.&#x5C5E;&#x6027;&#x540D; = &#x503C;</code>&#x8FD9;&#x79CD;&#x5F62;&#x5F0F;&#xFF0C;&#x4E3A;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5BF9;&#x5E94;&#x7684;&#x5C5E;&#x6027;&#x3002;</li>
<li>&#x4F7F;&#x7528;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x8BED;&#x6CD5;<code>&#x5BF9;&#x8C61;&#x540D;[&quot;&#x5C5E;&#x6027;&#x540D;&quot;] = &#x503C;</code>&#x8FD9;&#x79CD;&#x5F62;&#x5F0F;&#xFF0C;&#x4E3A;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5BF9;&#x5E94;&#x7684;&#x5C5E;&#x6027;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">//o&#x662F;&#x4E00;&#x4E2A;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x81EA;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;&#x7684;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">var</span> o = {};

<span class="hljs-comment">//&#x73B0;&#x5728;&#x60F3;&#x8BA9;&#x4ED6;&#x62E5;&#x6709;name age gender&#x7B49;&#x5C5E;&#x6027;</span>
<span class="hljs-comment">//&#x76F4;&#x63A5;&#x4F7F;&#x7528; &#x5BF9;&#x8C61;&#x540D;.&#x5C5E;&#x6027;&#x540D; = &#x503C;</span>
o.name = <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>;



<span class="hljs-comment">//&#x4F7F;&#x7528; &#x5BF9;&#x8C61;&#x540D;[&quot;&#x5C5E;&#x6027;&#x540D;&quot;] = &#x503C;</span>
o[<span class="hljs-string">&quot;age&quot;</span>] = <span class="hljs-number">18</span>;



<span class="hljs-comment">//&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6253;&#x5370;&#x67E5;&#x770B;&#x6548;&#x679C;</span>
<span class="hljs-built_in">console</span>.log(o.name);
<span class="hljs-built_in">console</span>.log(o.age);
</code></pre>
<p><strong><em>&#x6CE8;&#x610F;&#xFF1A;</em></strong></p>
<p>&#x5F53;&#x8981;&#x52A8;&#x6001;&#x7684;&#x4E3A;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5FC5;&#x987B;&#x4F7F;&#x7528;&#x5173;&#x8054;&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x5F0F;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-comment">//&#x63A5;&#x6536;&#x5230;&#x4E86;&#x7528;&#x6237;&#x7684;&#x8F93;&#x5165;</span>
<span class="hljs-keyword">var</span> str = prompt(<span class="hljs-string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x5C5E;&#x6027;&#x540D;&quot;</span>);

o = {};
<span class="hljs-comment">//o.str = &quot;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x65B0;&#x5C5E;&#x6027;&quot;; //&#x8FD9;&#x4E48;&#x5199;&#x662F;&#x4E0D;&#x5BF9;&#x7684;&#xFF0C;&#x4F1A;&#x7ED9;&#x5BF9;&#x8C61;&#x65B0;&#x589E;&#x4E00;&#x4E2A;str&#x5C5E;&#x6027;</span>
<span class="hljs-comment">//&#x6B63;&#x786E;&#x7684;&#x5199;&#x6CD5;&#x5982;&#x4E0B;</span>
o[str]=<span class="hljs-string">&quot;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x65B0;&#x5C5E;&#x6027;&quot;</span>;
</code></pre>
<h2 id="2&#x3001;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x8BBF;&#x95EE;&#x5F62;&#x5F0F;">2&#x3001;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;&#x7684;&#x8BBF;&#x95EE;&#x5F62;&#x5F0F;</h2>
<ul>
<li>&#x70B9;&#x8BED;&#x6CD5;&#xFF1A;<code>&#x5BF9;&#x8C61;&#x540D;.&#x5C5E;&#x6027;&#x540D;</code></li>
<li>&#x5173;&#x8054;&#x6570;&#x7EC4;&#xFF1A;<code>&#x5BF9;&#x8C61;&#x540D;[&#x5C5E;&#x6027;&#x540D;]</code></li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> o = {
    name:<span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span>,
    sayHello:<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x4F60;&#x597D;&#xFF0C;&#x6211;&#x53EB;&quot;</span>+ <span class="hljs-keyword">this</span>.name);
    }
};

<span class="hljs-comment">//&#x70B9;&#x8BED;&#x6CD5;</span>
<span class="hljs-built_in">console</span>.log(o.name);

<span class="hljs-comment">//&#x5173;&#x8054;&#x6570;&#x7EC4;&#x8BED;&#x6CD5;</span>
<span class="hljs-built_in">console</span>.log(o[<span class="hljs-string">&quot;name&quot;</span>]);

<span class="hljs-comment">//&#x8FD9;&#x4E24;&#x79CD;&#x7528;&#x6CD5;&#x540C;&#x6837;&#x9002;&#x7528;&#x4E8E;&#x65B9;&#x6CD5;</span>
o.sayHello();
o[<span class="hljs-string">&quot;sayHello&quot;</span>]();

<span class="hljs-comment">//&#x53EF;&#x4EE5;&#x5BF9;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x8FDB;&#x884C;&#x904D;&#x5386;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x503C;&#x5C31;&#x6253;&#x5370;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x65B9;&#x6CD5;&#x5C31;&#x8C03;&#x7528;</span>
<span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> k <span class="hljs-keyword">in</span> o){
    <span class="hljs-keyword">if</span> ( <span class="hljs-keyword">typeof</span> o[ k ] == <span class="hljs-string">&apos;function&apos;</span> ) {
        o[ k ]();
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-built_in">console</span>.log( <span class="hljs-string">&apos;log: &apos;</span> + o[ k ] );
    }
}
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../Sources/值类型和引用类型的特征.html" class="navigation navigation-prev " aria-label="Previous page: 值类型和引用类型的特征"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../Sources/dom操作复习.html" class="navigation navigation-next " aria-label="Next page: DOM操作复习"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
